package rpg002;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;

/**
 *
 * @author Smai
 *
 * Kun muokkaat menun kokoa ota huomioon kaikki muuttujat myös
 * menuitem luokan koot. tällä hetkellä nappuloiden koko on 128x24
 *
 *
 */
public class RightClickMenu {

  private ArrayList<MenuItem> menuItems = new ArrayList<MenuItem>();
  private ActionListener actionListener;
  private Map map;
  private int menuX;
  private int menuY;

  public RightClickMenu(ActionListener actionListener, Map map) {
    this.actionListener = actionListener;
    this.map = map;
    menuItems.add(new MenuItem("examine", 0, 128, 24));
    menuItems.add(new MenuItem("openclose", 25, 128, 24));
    menuItems.add(new MenuItem("examine", 50, 128, 24));
    menuItems.add(new MenuItem("talk", 75, 128, 24));

  }

  public void paint(Graphics gbi) {
    //gbi.setColor(Color.black);
    //gbi.fillRect(menuX, menuY, 128, 256);
    for (int i = 0; i < menuItems.size(); i++) {
      menuItems.get(i).paint(gbi, menuX, menuY+(i*25));
    }
  }

  public void setMenuCoords(int x, int y) {
    this.menuX = x;
    this.menuY = y;
  }

  public void checkMouseInfo(int x, int y) {
    Rectangle buttonBound;

    for (int i = 0; i < menuItems.size(); i++) {
      buttonBound = menuItems.get(i);
      if (buttonBound.contains(x, y)) {
        String action = menuItems.get(i).doAction();
        if (action.equals("examine")) {
          map.checkMouseInfo(menuX, menuY);
        }


        return;
      }

    }
  }
}
